<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    /**
     * Initiate the database connection.
     * @author Christophe Sourisse
     */
    protected function _initDatabase() {
        // Creating/Instanciating the connection to DB
        $db = Zend_Db::factory('Pdo_Mysql', array(
                    'host' => 'localhost',
                    'username' => 'root',
                    'password' => '',
                    'dbname' => 'whatsup'
                ));

        // Placing this connection into a register global to the application
        $registry = Zend_Registry::getInstance();
        $registry->set('my_db', $db);

        // Making it the connection by default
        Zend_Db_Table::setDefaultAdapter($db);
    }

    /**
     * Initiate the "doctype" declaration
     * @author Christophe Sourisse
     */
    protected function _initDoctype() {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
    }

    /**
     * Initiates session namespace
     * @author Matej Kollar
     */
    protected function _initSessionNamespace() {       

        // Creating/Instanciating the session namespace
        $sessionNamespace = new Zend_Session_Namespace('my_session_namespace');

        // Placing this session namespace into a register global to the application
        $registry = Zend_Registry::getInstance();
        $registry->set('my_session_namespace', $sessionNamespace);
    }

    /**
     * Add the reference to the jQuery library into the head of each page.
     * @author Christophe Sourisse
     */
    protected function _initJQuery() {
        $this->bootstrap('view');
        $this->getResource('view')
                ->headScript()
//                ->appendFile('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', 'text/javascript');
                ->appendFile('http://localhost/WhatsUpProject/public/js/library/jquery.min.js', 'text/javascript');
    }

    /**
     * Add the navigation menu to the layout.
     * @author Christophe Sourisse
     */
    protected function _initNagivation() {
       // Ensures that layout has been initialized 
       $this->bootstrap('layout');
       
       // Get the view from the layout resource
       $view = $this->getResource('layout')->getView();
       
       // Create navigation menu from the xml file
       $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
       $navigation = new Zend_Navigation($config);
       
       // Add navigation to the view
       $view->navigation($navigation);
       $view->headLink()->appendStylesheet('http://localhost/WhatsUpProject/public/css/navigation.css');
       $view->headScript()->appendFile('http://localhost/WhatsUpProject/public/js/navigation.js', 'text/javascript');
    }

    /**
     * Add the main CSS file to each view.
     * @author Christophe Sourisse
     */
    protected function _initStyle() {
        $this->bootstrap('layout');
        $view = $this->getResource('layout')->getView();
        $view->headLink()->appendStylesheet('/WhatsUpProject/public/css/main.css');
    }
    
}
